package com.czy.owner.widget;

import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.czy.owner.R;

/**
 * Created by King on 2016/5/17 0017.
 */
public class PageTitleView {
    private RelativeLayout rlTitleWrapper;
    private TextView tvTitle;
    private Button btnLeft, btnCenter,btnRight;

    /**
     * @param relativelayout  Title布局VIEW
     * @param centerText      Title文本
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText){
        rlTitleWrapper = relativelayout;
        init(centerText, null,false, false, false);
    }

    /**
     * @param relativelayout        Title布局VIEW
     * @param centerText            Title文本
     * @param isShowLeftButton      Title是否显示左按钮
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText, boolean isShowLeftButton) {
        rlTitleWrapper = relativelayout;
        init(centerText, null,isShowLeftButton, false, false);
    }

    /**
     * @param relativelayout
     * @param centerText
     * @param rightText
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText, String rightText) {
        rlTitleWrapper = relativelayout;
        init(centerText, rightText,false, false, true);
    }

    /**
     * @param relativelayout
     * @param centerText
     * @param isShowLeftButton
     * @param isShowRightButton
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText, boolean isShowLeftButton, boolean isShowRightButton) {
        rlTitleWrapper = relativelayout;
        init(centerText, null,isShowLeftButton, false, isShowRightButton);
    }

    /**
     * @param relativelayout
     * @param centerText
     * @param isShowLeftButton
     * @param isShowCenterButton
     * @param isShowRightButton
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText, boolean isShowLeftButton, boolean isShowCenterButton, boolean isShowRightButton) {
        rlTitleWrapper = relativelayout;
        init(centerText, null,isShowLeftButton, isShowCenterButton, isShowRightButton);
    }

    /**
     * @param relativelayout
     * @param centerText
     * @param rightText
     * @param isShowLeftButton
     * @param isShowCenterButton
     * @param isShowRightButton
     */
    public PageTitleView(RelativeLayout relativelayout, String centerText, String rightText, boolean isShowLeftButton, boolean isShowCenterButton, boolean isShowRightButton) {
        rlTitleWrapper = relativelayout;
        init(centerText, rightText,isShowLeftButton, isShowCenterButton, isShowRightButton);
    }
    /**
     * @param centerText            Title文本
     * @param rightText             Title右按钮文本
     * @param isShowLeftButton      Title是否显示左按钮
     * @param isShowCenterButton    Title是否显示中按钮
     * @param isShowRightButton     Title是否显示右按钮
     */
    private void init(String centerText, String rightText, boolean isShowLeftButton,boolean isShowCenterButton,boolean isShowRightButton) {

        tvTitle = (TextView) rlTitleWrapper.findViewById(R.id.tv_page_title_center);
        btnLeft = (Button) rlTitleWrapper.findViewById(R.id.btn_page_title_left);
        btnCenter= (Button) rlTitleWrapper.findViewById(R.id.btn_page_title_center);
        btnRight = (Button) rlTitleWrapper.findViewById(R.id.btn_page_title_right);

        if (centerText != null && !"".equals(centerText))
            tvTitle.setText(centerText);

        if (isShowLeftButton) {
            btnLeft.setVisibility(View.VISIBLE);
        }else{
            btnLeft.setVisibility(View.GONE);
        }
        if (isShowCenterButton) {
            btnCenter.setVisibility(View.VISIBLE);
        }else{
            btnCenter.setVisibility(View.GONE);
        }
        if (isShowRightButton ) {
            if(rightText != null && !"".equals(rightText) ) btnRight.setText(rightText);
            btnRight.setVisibility(View.VISIBLE);
        }else {
            btnRight.setVisibility(View.GONE);
        }
    }
    /**
     * 获取中间的TextView控件
     *
     * @return  中间的TextView控件
     */
    public TextView getCenterTextView() {
        return tvTitle;
    }
    /**
     * 获取左边的按钮，默认是返回按钮
     *
     * @return
     */
    public Button getLeftButton() {
        return btnLeft;
    }
    /**
     * 获取中间的按钮，为下拉预留
     *
     * @return
     */
    public Button getCenterButton() {
        return btnCenter;
    }
    /**
     * 获取右边的正常按钮
     *
     * @return
     */
    public Button getRightButton() {
        return btnRight;
    }

    public RelativeLayout getTitleWrapper(){
        return rlTitleWrapper;
    }
}
